﻿/*
This file is under Microsoft Public License (MS-PL)
Copyright Yohann MARTEL.  All rights reserved.
Codeplex: http://amf.codeplex.com
AMF Website: http://www.ymartel.com/aspnet-mobile-framework/
*/
using System.ComponentModel;
using System.Web.UI;

namespace Mobile.WebControls
{
    [ToolboxData("<{0}:LinkContainer runat=server></{0}:LinkContainer>")]
    public class LinkContainer : BaseLink
    {
        #region Properties
        [Browsable(false), DefaultValue(null), PersistenceMode(PersistenceMode.InnerProperty),
         TemplateContainer(typeof(BindableTemplate))]
        public ITemplate Content { get; set; }

        [Bindable(true)]
        public object DataItem { get; set; }

        public override ControlCollection Controls
        {
            get
            {
                EnsureChildControls();
                return base.Controls;
            }
        }
        #endregion

        #region Contructor
        public LinkContainer() : base()
        {
        }
        #endregion

        #region Methods
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            if (Content != null)
            {
                BindableTemplate contentContainer = new BindableTemplate();
                contentContainer.DataItem = DataItem;
                Content.InstantiateIn(contentContainer);
                Controls.Add(contentContainer);
                contentContainer.DataBind();
            }

        }
        #endregion
    }
}
